package com.micro.modual.service.impl;

import com.micro.common.MicroResponseCode;
import com.micro.core.exception.BizException;
import com.micro.core.frame.service.impl.AbstractBasicsServiceImpl;
import com.micro.core.resp.RespJson;
import com.micro.modual.entity.CartItem;
import com.micro.modual.extension.CartItemExtension;
import com.micro.modual.mapper.CartItemMapper;
import com.micro.modual.model.bo.cartitem.CartItemBO;
import com.micro.modual.service.CartItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
*  <h1>商品购物车  实现</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:11:10
 */
@Service("cartItemService")
public class CartItemServiceImpl extends AbstractBasicsServiceImpl<CartItem,Long> implements CartItemService {

    @Autowired
    private CartItemMapper cartItemMapper;

    /**
     * <h2>新增商品购物车详情</h2>
     * @param cartItemBO {@link CartItemBO} 商品购物车 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson addCartItem(CartItemBO cartItemBO) {
        CartItem cartItem = CartItemExtension.converAddCartItem(cartItemBO);
        cartItemMapper.insertSelective(cartItem);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(), MicroResponseCode.SUCCESS.getResponseMessage());
    }

    /**
     * <h2>修改商品购物车详情</h2>
     * @param cartItemBO  {@link CartItemBO} 商品购物车 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson editCartItem(CartItemBO cartItemBO) {
        CartItem cartItem = CartItemExtension.converEditCartItem(cartItemBO);
        cartItemMapper.updateByPrimaryKeySelective(cartItem);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

    /**
     * <h2>根据主键编号删除商品购物车信息</h2>
     * @param id  商品购物车 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */

    @Override
    public RespJson deleteCartItem(Long id) {
        cartItemMapper.deleteByPrimaryKey(id);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

}
